<!DOCTYPE html>
<html class="no-js" lang="zxx">

<head>
    <meta charset="utf-8" />
    <meta http-equiv="x-ua-compatible" content="ie=edge" />
    <title>Post Job - JobGrids Job Portal HTML Template.</title>
    <meta name="description" content="" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="shortcut icon" type="image/x-icon" href="assets/images/favicon.svg" />
    <!-- Place favicon.ico in the root directory -->

    <!-- Web Font -->
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap"
        rel="stylesheet">

    <!-- ========================= CSS here ========================= -->
    <link rel="stylesheet" href="assets/css/bootstrap.min.css" />
    <link rel="stylesheet" href="assets/css/LineIcons.2.0.css" />
    <link rel="stylesheet" href="assets/css/animate.css" />
    <link rel="stylesheet" href="assets/css/tiny-slider.css" />
    <link rel="stylesheet" href="assets/css/glightbox.min.css" />
    <link rel="stylesheet" href="assets/css/main.css" />

</head>

<body>
    <!--[if lte IE 9]>
      <p class="browserupgrade">
        You are using an <strong>outdated</strong> browser. Please
        <a href="https://browsehappy.com/">upgrade your browser</a> to improve
        your experience and security.
      </p>
    <![endif]-->

    <div id="loading-area"></div>

    <!-- Start Header Area -->
    <header class="header">
      <div class="navbar-area">
        <div class="container">

          <div class="row align-items-center">

            <div class="col-lg-12">
              <nav class="navbar navbar-expand-lg">
                <a class="navbar-brand logo" href="index-hr.html">
                  <img class="logo1" src="assets/images/logo/logo.svg" alt="Logo" />
                </a>
                <button class="navbar-toggler" type="button" data-toggle="collapse"
                        data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
                        aria-expanded="false" aria-label="Toggle navigation">
                  <span class="toggler-icon"></span>
                  <span class="toggler-icon"></span>
                  <span class="toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse sub-menu-bar" id="navbarSupportedContent">
                  <ul id="nav" class="navbar-nav ml-auto">
                    <li class="nav-item">
                      <a  href="index.html">主页</a>
                    </li>



                    <li class="nav-item">
                      <a  href="browse-jobs.html">职位搜索</a>
                    </li>

                    <li class="nav-item active" ><a href="#" class="active">职位管理 </a>
                      <ul class="sub-menu">
                        <li><a class="active" href="post-job.html">发布职位</a></li>
                        <li><a href="manage-jobs.html">职位查看与编辑</a></li>
                        <li><a  href="have-manage-resumes.html">已处理申请</a></li>
                        <li><a  href="manage-resumes.html">待处理申请</a></li>

                      </ul>
                    </li>



                    <li class="nav-item">
                      <a href="blog-grid-sidebar.html">论坛</a></li>
                    </li>

                    <li class="nav-item"><a href="contact.html">联系我们 </a> </li>


                    <li class="nav-item"><a href="#">其他</a>
                      <ul class="sub-menu">
                        <!-- <li><a href="index.html" onclick="logout()">Log Out</a></li> -->
                        <li><a onclick="checkloginuser()">Personal Info</a></li>
                        <li><a href="about-us.html" onclick="addtoken()">About Us</a></li>
                        <li><a href="job-list.html">Job List</a></li>
                        <li><a href="job-details.html">Job Details</a></li>
                        <li><a href="resume.html">Resume Page</a></li>
                        <li><a href="privacy-policy.html">Privacy Policy</a></li>
                        <li><a href="faq.html">Faq</a></li>
                        <li><a href="pricing.html">Our Pricing</a></li>
                        <li><a href="404.html">404 Error</a></li>
                        <li><a href="mail-success.html">Mail Success</a></li>
                      </ul>
                    </li>

                    <li class="nav-item">
                      <a href="#">个人中心</a>
                      <ul class="sub-menu">
                        <li><a href="showhrinfo.html">信息编辑</a></li>
                        <li><a href="job-alerts.html">申请进度</a></li>
                        <li><a href="job-alerts.html">消息提醒</a></li>
                        <li><a href="manage-blog.html">管理博客</a></li>
                      </ul>
                    </li>
                    <li class="nav-item login">

                      <a href="showhrinfo.html" id="shownameid" >
                      </a>
                      <ul class="sub-menu">
                        <li><a href="index.html" onclick="logout()">退出登录</a></li>
                      </ul>
                    </li>
                  </ul>
                </div>
                <!-- navbar collapse -->
                <!--登录显示用户名的地方，点击进入到个人中心界面-->



              </nav>
              <!-- navbar -->
            </div>
          </div>
          <!-- row -->
        </div>
        <!-- container -->
      </div>
      <!-- navbar area -->
    </header>
    <!-- End Header Area -->


    <section class="job-post section">
        <div class="container">
            <div class="row">
                <div class="col-lg-10 offset-lg-1 col-12">
                    <div class="job-information">
                        <h3 class="title">发布职位</h3>

                      <form  id="postjobform" method="post" onsubmit="return false" >
                            <div class="row">

                              <div class="col-lg-12">
                              <div class="form-group">
                                <label>职位名称*</label>
                                <input class="form-control" type="text" name="title">
                              </div>
                            </div>

<!--                              <div class="col-lg-6 col-md-6">-->
<!--                                <div class="form-group">-->
<!--                                  <label>职位数目</label>-->
<!--                                  <input class="form-control" type="text" name="jobid">-->
<!--                                </div>-->
<!--                              </div>-->

<!--                              <div class="col-lg-6 col-md-6">-->
<!--                                <div class="form-group">-->
<!--                                  <label>HR账号</label>-->
<!--                                  <input class="form-control" type="text" name="hrid">-->
<!--                                </div>-->
<!--                              </div>-->

                              <div class="col-lg-6 col-md-6">
                                <div class="form-group">
                                  <label>发布状态</label>
                                  <input class="form-control" type="text" name="poststat">
                                </div>
                              </div>

                              <div class="col-lg-6 col-md-6">
                                <div class="form-group">
                                  <label>招聘状态</label>
                                  <input class="form-control" type="text" name="recruitstat">
                                </div>
                              </div>



                                <div class="col-lg-6 col-md-6">
                                    <div class="form-group">
                                        <label>职业类型</label>
                                        <select class="select" id="jobkindid" name="jobkind">
                                            <option value="1">全职</option>
                                            <option value="2">Part Time</option>
                                            <option value="3">Contract</option>
                                            <option value="4">Internship</option>
                                            <option value="5">Office</option>
                                        </select>
                                    </div>
                                </div>


                              <div class="col-lg-6 col-md-6">
                                <div class="form-group">
                                  <label>更新时间 </label>
                                  <input class="form-control" type="text" name="updatetime">
                                </div>
                              </div>

                                <div class="col-lg-6 col-md-6">
                                    <div class="form-group">
                                        <label>薪资范围</label>
                                        <select class="select" id="salrayid" name="salary">
                                            <option value="1">Default</option>
                                            <option value="2">20000 To 30000</option>
                                            <option value="3">40000 To 50000</option>
                                            <option value="4">60000 To 70000</option>
                                            <option value="5">80000 To 90000</option>
                                        </select>
                                    </div>
                                </div>

                              <div class="col-lg-12">
                                <div class="form-group">
                                  <label>工作地点</label>
                                  <input class="form-control" type="text" name="loc">
                                </div>
                              </div>

                              <div class="col-lg-12">
                                <div class="form-group">
                                  <label>该工作要求的基本学历</label>
                                  <input class="form-control" type="text" name="educ">
                                </div>
                              </div>

                                <div class="col-lg-12">
                                    <div class="form-group">
                                        <label>工作描述</label>
                                        <textarea name="jobdesc" class="form-control" rows="5"></textarea>
                                    </div>
                                </div>


                              <div class="col-lg-12">
                                <div class="form-group">
                                  <label>需要求职者有哪些工作经验？</label>
                                  <textarea name="exprdesc" class="form-control" rows="5"></textarea>
                                </div>
                              </div>

                            </div>

                                <div class="col-lg-12 button">
                                    <button class="btn" id="jobpostbtn" onclick="signup()">
                                        发布职位
                                    </button>
                                </div>



                        </form>

                    </div>
                </div>
            </div>
        </div>
    </section>



                        <!-- Start Footer Area -->
<footer class="footer">
        <div class="footer-bottom">
            <div class="container">
                <div class="inner">
                    <div class="row">
                        <div class="col-lg-6 col-md-6 col-12">
                            <div class="left">
                                <p><a target="_blank" >软件工程大作业</a></p>
                            </div>
                        </div>
                        <div class="col-lg-6 col-md-6 col-12">
                            <div class="right">
                                <ul>
                                    <li><a href="privacy-policy.html">用户手册</a></li>
                                    <li><a href="#">项目文档</a></li>
                                    <li><a href="https://gitee.com/Yuan-Wi/software-engineering-team/tree/master/">gitee</a></li>
                                    <li><a href="contact.html">联系我们</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- End Footer Middle -->
    </footer>
    <!--/ End Footer Area -->

    <!-- ========================= scroll-top ========================= -->
    <a href="#" class="scroll-top btn-hover">
        <i class="lni lni-chevron-up"></i>
    </a>

    <!-- ========================= JS here ========================= -->
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>

    <script src="assets/js/wow.min.js"></script>
    <script src="assets/js/tiny-slider.js"></script>
    <script src="assets/js/glightbox.min.js"></script>
    <script src="assets/js/main.js"></script>
    <script src="assets/js/bootstrap.min.js"></script>
    <script type="text/javascript">
      //===========表单数据传到后台


       //================注册登录相关
          //像后端传本地浏览器保存的token（当前登录用户）点击首页跳转的页面
    function checkloginuser(){
        //window.location.reload();

      $.ajax({
      url: "http://localhost:8080/mycheckloginuser",
      type: "GET",
      data: {token : window.localStorage.getItem("user")?window.localStorage.getItem("user"):"notoken"},
      success: function(result){
       // alert(result.code);
        if(result.code==200){
          if(result.msg=="hrlogin"){

          location.href="http://localhost/static/html/showhrinfo.html";
          }
          else if(result.msg=="employeelogin"){window.location.href="http://localhost/static/html/showseekerinfo.html";}
        }
        else {
          alert(result.code+result.msg);
          }
      },
      error: function(){
      alert("请刷新重试");
      },
    });

    };
  //其他业务请求从本地浏览器中存的token获取加入请求头

  function logout(){
   window.localStorage.removeItem('user');
   location.href="http://localhost/static/html/index.html";
  };
  var loginuserinfo;//当前登录用户的角色和id
  /*解析token*/
  function sparsetoken(){
  var token;
    $(function(){
    token = window.localStorage.getItem("user");//这可以得到当前登录用户的token
    alert("user="+token);
    alert(window.location.href);
    //data.data.normal_login_token为发送Ajax获取到的token信息
  var strings = token.split(".");//通过split()方法将token转为字符串数组
  //取strings[1]数组中的第二个字符进行解析
  var userinfo = JSON.parse(decodeURIComponent(escape(window.atob(strings[1].replace(/-/g, "+").replace(/_/g, "/")))));
  loginuserinfo = userinfo;//赋给全局变量
  //然后可以拿到解析后的数据，可以console.log()打印下，roleid是在表中的id，loginrole=hrlogin或seekerlogin
  alert(userinfo.roleid+userinfo.loginrole+'userinfo');

    });

  };


     //===========最初需要完成名字的显示
    $(document).ready(function(){


           /*   alert("新方法");*/
              $.ajax({
      url: "http://localhost:8080/mylogingetusername",
      type: "GET",
      data: {token : window.localStorage.getItem("user")?window.localStorage.getItem("user"):"notoken"},
      success: function(result){
       // alert(result.code);
        if(result.code==200){
        alert(result.msg);
        document.getElementById('shownameid').textContent = "欢迎"+result.msg+"登录";
        }
        else {
          alert(result.code+result.msg);
          }
      },
      error: function(){
      alert("请刷新重试");
      },
    });
          });

      function signup(){
        token = window.localStorage.getItem("user");//这可以得到当前登录用户的token
        //alert("user="+token);
        //alert(window.location.href);
        //data.data.normal_login_token为发送Ajax获取到的token信息
        var strings = token.split(".");//通过split()方法将token转为字符串数组
        //取strings[1]数组中的第二个字符进行解析
        var userinfo = JSON.parse(decodeURIComponent(escape(window.atob(strings[1].replace(/-/g, "+").replace(/_/g, "/")))));
        //loginuserinfo = userinfo;//赋给全局变量
        //然后可以拿到解析后的数据，可以console.log()打印下，roleid是在表中的id，loginrole=hrlogin或seekerlogin
        alert(userinfo.roleid+userinfo.loginrole+'userinfo');

        //var hrIdStr = $('[name=hrid]').val();
        //var hrId = parseInt(hrIdStr, 10);  // 将字符串转换为整数
        var hrId =userinfo.roleid;
        //alert(hrId+'hrId');
        alert('hrId 类型: ' + typeof hrId + ', 值: ' + hrId);

        if (isNaN(hrId)) {
          alert('请输入有效的HR ID');
          return;
        }

        // var data = {
        //   hrId: hrId
        // };

        var formData = $('#postjobform').serializeArray();
        formData.push({ name: "hrid", value: hrId });

        //alert($('#postjobform').serialize());
        alert($.param(formData)); // 显示序列化后的表单数据

        $.ajax({
          type: "POST",
          dataType: "json",
          url: "http://localhost:8080/jobpost",
          //data: $('#postjobform').serialize(),
          data: $.param(formData), // 使用包含hrId的表单数据
          success: function(result){
            if(result.code==200){
              alert("发布工作岗位成功！");
              /*页面重定向到职位查看与编辑页面*/
              window.location.href="http://localhost/static/html/manage-jobs.html";
            }
            else{
              alert(result.code);
            }
          },
          error : function(){
            alert("发布工作失败!");
          },
        });
      }

    </script>
</body>

</html>
